<template>
  <div class="search_result"   v-if="show">
              <h2>上期强推</h2>
    <ul >
      <li v-for="(item,index) in searchResult" :key="index">
        <span class="s1">{{item.type}}</span>
        <span class="s2" @click="jump(item)">
          <a>{{item.bookname}}</a>
        </span>
        <span class="s5">
          {{item.author}}
        </span>
      </li>

    </ul>

  </div>
</template>
<script>
export default {
  name: 'NovelList',
  props: {
    searchResult: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      show: false
    }
  },

  methods: {
    jump (item) {
      // 点击书名，触发SETNAME函数，将书名传递过去，
      this.$store.commit('SETNAME', item.bookname)
      // 跳转章节内页面
      this.$router.push(`/chapter/${item.href}`)
    }
  },
  watch: {
    searchResult (newval, oldval) {
      // console.log(newval, oldval)
      if (newval.length !== 0) {
        this.show = true
      }
    }

  }
}
</script>
<style lang="less" scoped>
.search_result {
    background: #FEF9EF;
  border: 3px solid #C3DFEA;
  margin-left: 10px;
  width: 265px;
  height: 340px;
  ul {
      padding: 0 10px;
    list-style: none;
    // 左边padding没有距离
    // padding-inline-start: 0;
    // padding-top: 15px;
    li:first-child{
      padding-top: 10px;
    }
    li {
      display: flex;
      padding: 5px 0 0;
      border-bottom: 1px solid #DDDDDD;;
      // overflow: hidden;
      line-height: 27px;
      height: 26px;
      span {
        font-size: 12px;
        a {
          cursor: pointer;
        }
      }
      .s1 {
      width: 80px;
      display: inline-block;
      margin:0;
      }
      .s2{ display: inline-block;
        flex: 0.6;
        margin: 0;
      }
      .s2:hover
       {
        background-color: pink;
        transition: 1s;
      }

      .s5{
        text-align: right;
        // float: right;

        text-align: right;
        flex: 0.5;
        margin: 0;
      }
    }
  }
}
.search_result{
  h2{
    background-color: #E1ECED;
    border-bottom: 1px solid #DDD;
    font-size: 14px;
    font-weight: 700;
    height: 30px;
    line-height: 30px;
    overflow: hidden;
    margin: 0;
    padding: 0 0 0 10px;
  }
}
</style>
